<?php


namespace app\seller\controller;

use app\admin\model\Seller;
use think\Db;


class Base extends Common
{
    public $seller_id = 0;
    public $shop_id = 0;
    public $shop;
    public $seller;

    public function __construct()
    {
        parent::__construct();
        $seller_token = input('_token', '');
        $shop_id = input('_shop_id');
        if (!$seller_token) {
            return $this->error('请先登录', [], -200);
        }

        $data = Db::name('seller')->where([
            'token' => $seller_token,
            "state" => 'normal',
        ])->find();
        if (!$data) {
            return $this->error('请先登录', [], -200);
        }
        $this->seller = $data;
        $this->seller_id = $data['id'];
        if (request()->controller() != 'Shop') {
            if (!$shop_id) {
                return $this->error('请先选择门店', [], -210);
            }
            $shop = Db::name('category')->where([
                'id' => $shop_id,
                "seller_id" => $this->seller_id,
            ])->find();
            if (!$shop) {
                return $this->error('请先选择门店', [], -210);
            }
            $this->shop = $shop;
            $this->shop_id = $shop['id'];
        }
    }

    public function fangjianIds()
    {
        $ids = Db::name('fangjian')->where('category_id', $this->shop_id)->column('id');
        if ($ids) {
            return $ids;
        }
        return [-99];
    }

}
